package org.proxycine.gestsalles.model.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.proxycine.gestsalles.model.entities.Employe;
import org.proxycine.gestsalles.model.entities.RoleEmploye;

public final class LoginDao extends Adapter {
	
	private static LoginDao instance;
	
	private LoginDao() {
		instance = this;
	}
	
	public static LoginDao getInstance() {
		if(instance == null)
			instance = new LoginDao();
		
		return instance;
	}
	
	public Employe valideLogin(String login, String password) {
		
		Employe employe = null;
		
		String request = "SELECT * from Employe " + 
			"WHERE login = '" + login + "' " +
			"AND password = '" + password + "'";
		try {
			ResultSet rs = getStatement().executeQuery(request);
			
			if (rs.next()) {
				employe = new Employe(rs.getInt(1), rs.getString(2), 
						rs.getString(3), rs.getString(4), 
						rs.getString(5), RoleEmploye.valueOf(rs.getString(6)));
			}
			
			rs.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return employe;
		
	}
	
}
